package org.japo.java.swing.igu;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.HeadlessException;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.japo.java.swing.listeners.GEA;
import org.japo.java.swing.listeners.GEP;

public class IGU extends JFrame {
//Declarar variables necesarias

    private JLabel lblX;
    private JLabel lblY;
    private JLabel lblAncho;
    private JLabel lblAlto;
    private JTextField txfX;
    private JTextField txfY;
    private JTextField txfAncho;
    private JTextField txfAlto;

    public IGU() throws HeadlessException {
        iniciarComponentes();
    }
    JPanel pnlPrincipal = new JPanel(null);

    private void iniciarComponentes() {

        pnlPrincipal.setLayout(null);

        //Valores de la fuente
        Font f = new Font("Calibri", Font.BOLD + Font.ITALIC, 16);

        // Borde principal
//        Border brdPrincipal = new EmptyBorder(10, 10, 10, 10);
//        Gestor de eventos de accion
        GEA gea = new GEA(this);
        GEP gep = new GEP(this);

        //Label X
        lblX = new JLabel();
        lblX.setLocation(10, 10);
        lblX.setText("X");
        lblX.setHorizontalAlignment(JLabel.RIGHT);
        lblX.setFont(f);
        lblX.setSize(new Dimension(80, 30));
        pnlPrincipal.add(lblX);

        //Campo de texto de la X
        txfX = new JTextField("300");
        txfX.setLocation(110, 10);
//        txfX.setText(xp + "");
        txfX.setSize(new Dimension(100, 30));
        txfX.setFont(f);
        txfX.addActionListener(gea);
        pnlPrincipal.add(txfX);

        //Label Y
        lblY = new JLabel();
        lblY.setLocation(10, 40);
        lblY.setText("Y");
        lblY.setHorizontalAlignment(JLabel.RIGHT);
        lblY.setFont(f);
        lblY.setSize(new Dimension(80, 30));
        pnlPrincipal.add(lblY);

        //Campo de texto de la X
        txfY = new JTextField("300");
        txfY.setLocation(110, 40);
        txfY.setSize(new Dimension(100, 30));
        txfY.setFont(f);
        txfY.addActionListener(gea);
        pnlPrincipal.add(txfY);

        //Label Ancho
        lblAncho = new JLabel();
        lblAncho.setLocation(10, 70);
        lblAncho.setText("Ancho");
        lblAncho.setHorizontalAlignment(JLabel.RIGHT);
        lblAncho.setFont(f);
        lblAncho.setSize(new Dimension(80, 30));
        pnlPrincipal.add(lblAncho);

        //Campo de texto del Ancho
        txfAncho = new JTextField("300");
        txfAncho.setLocation(110, 70);
        txfAncho.setSize(new Dimension(100, 30));
        txfAncho.setFont(f);
        txfAncho.addActionListener(gea);
        pnlPrincipal.add(txfAncho);

        //Label Alto
        lblAlto = new JLabel();
        lblAlto.setLocation(10, 100);
        lblAlto.setText("Alto");
        lblAlto.setHorizontalAlignment(JLabel.RIGHT);
        lblAlto.setFont(f);
        lblAlto.setSize(new Dimension(80, 30));
        pnlPrincipal.add(lblAlto);

        //Campo de texto del Alto
        txfAlto = new JTextField("170");
        txfAlto.setLocation(110, 100);
        txfAlto.setSize(new Dimension(100, 30));
        txfAlto.setFont(f);
        txfAlto.addActionListener(gea);
        pnlPrincipal.add(txfAlto);

        // Ventana principal
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addComponentListener(gep);
        setLocation(100, 10);
        setTitle("Pruebas X, Y, Ancho y Alto");
        setContentPane(pnlPrincipal);
        setResizable(false);
        setSize(300, 170);
        setLocationRelativeTo(null);

    }

    public void procesarDimensiones(Object o) {
        setLocation(Integer.parseInt(txfX.getText()), Integer.parseInt(txfY.getText()));
        setSize(Integer.parseInt(txfAncho.getText()), Integer.parseInt(txfAlto.getText()));
       
    }

    public void procesarMovimiento() {
        int x = this.getX();
        int y = this.getY();
    
        txfX.setText(x + "");
        txfY.setText(String.valueOf(y));
    
    }
}
